<template>
    <div class="content">
        <TableLayout form-title="">
            <div slot="form-title" class="table-title"></div>
            <el-form :model="formInline" class="formInline" :rules="rules" ref="formInline" label-width="76px" slot="form" label-position="right">          
                <el-row :gutter="41"> 
                    <el-col :span="8">
                        <el-form-item label="姓名">
                            <el-input v-model="formInline.parentName" placeholder="请输入家长姓名" :maxlength="12" ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="手机号" prop="phone">
                            <el-input v-model="formInline.phone" placeholder="请输入家长手机号" :maxlength="11"></el-input>
                        </el-form-item>
                    </el-col>
                     <el-col :span="8">
                        <el-form-item label="e学云ID号" prop="EId">
                            <el-input v-model="formInline.EId" placeholder="请输入e学云ID号" :maxlength="10" ></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
              
                <div class="top-line">
                    <el-button type="primary" @click="onSubmit('formInline')">查询</el-button>
                </div>
            </el-form>
            <div class="table-title" slot="table-title">
            </div>
            <el-table :data="dataApply" style="width: 100%" border @selection-change="handleSelectionChange" v-loading="loading" ref="multipleTable">
                
                <el-table-column  align="center" label="e学云ID号" min-width="100">
                     <template scope="scope">
                         {{scope.row.exueId?scope.row.exueId:'--'}}
                     </template>
                </el-table-column>
                
                <el-table-column  align="center" label="家长姓名" min-width="110">
                    <template scope="scope">
                         {{scope.row.parentName?scope.row.parentName:'--'}}
                     </template>
                </el-table-column>
                
                <el-table-column align="center" label="手机号" min-width="140">
                     <template scope="scope">
                         {{scope.row.phone?scope.row.phone:'--'}}
                     </template>
                </el-table-column>

                <el-table-column align="center" label="关联学生数" min-width="140">
                     <template scope="scope">
                         {{scope.row.studentNum?scope.row.studentNum:'0'}}
                     </template>
                </el-table-column>

                <el-table-column prop="createTime" align="center" label="创建时间" min-width="170">
                    <template scope="scope">{{scope.row.createTime | filterCreateTime}}</template>    
                </el-table-column> 

                <el-table-column align="center" label="最后登录时间" min-width="170">
                    <template scope="scope">{{scope.row.lastLoginTime | filterCreateTime}}</template>    
                </el-table-column>

                <el-table-column  label="其他操作" min-width="90">
                    <template scope="scope">    
                        <el-button type="text" class="btn-success" @click="checked(scope.row)">查看</el-button>
                    </template>
                </el-table-column>           
            </el-table>
            <div class="pagination-container" style="text-align:right">
                <el-pagination
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="listQuery.total"
                    :current-page.sync="listQuery.page"
                    :page-sizes="config.pageSizes"
                    :page-size="config.pageSize"
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange">
                </el-pagination>
            </div>
        </TableLayout>
    </div>
</template>

<script>
import TableLayout from 'components/TableLayout';
import {queryList} from 'api/parentManagement';
import validate from '@/utils/validate';
import { mapState, mapActions, mapGetters } from 'vuex';

export default{
    name: 'parentManageList',
    components: {TableLayout},
    data() {
        return {
            formInline: {// form表单数据
                leaderName: '',
                phone: '',
                schoolId: '',
                schoolNameList: [],
                EId: '',
                parentName: ''
            },
            schoolList: [],
            dataApply: [],
            subjectDetail: false,
            subject: '',
            dataNum: 1, // 表格1显示条数，初始为1
            listQuery: {// 分页
                page: 1,
                total: 0
            },
            dialog: {
                dialogFormVisible: false
            },
            dataForm: {

            },
            loading: true,
            schoolLoading: false,
            multipleSelection: [],
            rules: {
                EId: [...validate.exueCode()],
                phone: [...validate.phone()]
            }
        }
    },
    computed: {
        ...mapState({
            config: state => state.config.table,
            cacheUpdated: state => state.app.cacheUpdated// 局部刷新列表 2018-1-10bycuihd
        }),
        ...mapGetters([
            'uid',
            'schoolId'
        ])
    },
    filters: {
        filterCreateTime(val) {           
            if (val) {
                return val.substr(0, val.length-2) 
            } else {
                return '--'
            }
        }

    },
    watch: {// 局部刷新列表 2018-1-10bycuihd
        cacheUpdated(val) {
            val && this.searchFetchData();
        }
    },
    // 初始化
    created() {      
        this.searchFetchData();
    },
    
    methods: {
        // 全局获取行数
        ...mapActions(['ChangePageSize']),
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },
        // 分页
        handleSizeChange(val) {
            this.listQuery.page = 1;
            this.loading = true;
            this.ChangePageSize(val);
            this.searchFetchData();
        },
        handleCurrentChange(val) {
            this.loading = true;
            this.listQuery.page = val;
            this.searchFetchData();
        },
        // 查询列表
        searchFetchData() {
            queryList(this.listQuery.page, this.config.pageSize, this.schoolId, 
            this.formInline.parentName, this.formInline.EId, this.formInline.phone).then(response => {              
                if (response.data.status==200) {
                    this.dataApply = response.data.content.list;
                    this.listQuery.total = response.data.content.pagination.total;
                    this.loading = false;    
                } else {
                    this.$message({
                        type: 'warning',
                        message: response.data.errorMsg
                    })
                }
            }).catch(() => {
                this.$message.error(response.data.errorMsg);
            });
        },

        // 表单查询
        // onSubmit() {
        //     this.loading = true;
        //     this.searchFetchData();
        // },
               // 点击查询 
        onSubmit(ruleForm) {
            this.$refs[ruleForm].validate((valid) => {
                if (valid) {
                    this.listQuery.page = 1;
                    this.loading = true;
                    this.searchFetchData();
                } else {
                    return false;
                }
            });
        },
        // 跳转
        checked(row) {
            this.$router.push({path: `/parentManagement/checkParentManage/${row.parentId}/${row.userId}`});
        }
    }
}
</script>
<style lang="scss" scoped>
.content {
    position: relative;
    padding: 0px;
    $bgcolor:#fff;
    label{
        text-align:left;
    }
    .el-tag{
            margin-left:5px;
            background:#f9f9f9;
            color:#444;
        }
    .formInline {
        .formBtn{
            width: 100%;
            height: 70px;
            border-top: 1px solid #dddddd;
            position: relative;
            .btnPosition{
                position: absolute;
                right:0px; 
                top: 18px;
            }
        }
    }
    .footer{
            text-align:center;
            margin-top:40px;
        }
    .footer .el-button{
            padding:10px 40px;
        }
}
</style> 